package com.lc.qianrenshiye.conn;

import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.http.note.HttpInlet;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/12/4.
 */
@HttpInlet(Conn.GAINS_COST)
public class MycastListPost extends BaseAsyPost<MycastListPost.MycastListEntity> {

    public String sid, time, type, start, end;

    public MycastListPost(AsyCallBack<MycastListEntity> asyCallBack) {
        super(asyCallBack);
    }

    @Override
    protected MycastListEntity parser(JSONObject object) throws Exception {

        TOAST = object.optString("message");

        if (object.optInt("code") == 200) {

            MycastListEntity mycastListEntity = new MycastListEntity();

            mycastListEntity.total = object.optString("total");
            mycastListEntity.start = object.optString("start");
            mycastListEntity.end = object.optString("end");

            JSONArray array = object.optJSONArray("list");

            for (int i = 0; i < array.length(); i++) {

                JSONObject entityObject = array.optJSONObject(i);

                MycastEntity mycastEntity = new MycastEntity();

                mycastEntity.time = entityObject.optString("time");
                mycastEntity.title = entityObject.optString("title");
                mycastEntity.name = entityObject.optString("name");
                mycastEntity.price = entityObject.optString("price");
                mycastEntity.num = entityObject.optString("num");
                mycastEntity.total = entityObject.optString("total");
                mycastEntity.picurl = Conn.IMAGE_URL + entityObject.optString("picurl");

                mycastListEntity.mycastEntityList.add(mycastEntity);

            }

            return mycastListEntity;

        }

        return null;
    }

    public static class MycastListEntity {

        public String total, start, end;
        public List<MycastEntity> mycastEntityList = new ArrayList<>();

    }

    public static class MycastEntity {

        public String time, title, name, price, num, total, picurl;

    }


}
